<template>
    <div class="">
        <!-- 条件筛选-----查询 -->
        <el-form :inline="true">
            <div style="display: flex; justify-content: space-between;">
                <div>
                    <el-form-item>
                        <el-input v-model="userid" clearable placeholder="用户ID" style="width: 120px;" />
                    </el-form-item>
                    <el-form-item>
                        <el-input v-model="key" clearable placeholder="用户名、邮箱、地址" style="width: 180px;" />
                    </el-form-item>
                    <el-form-item>
                        <label>币种：</label>
                        <el-select v-model="coinid" placeholder="币种">
                            <el-option label="全部" :value="0" />
                            <el-option v-for="item in Object.keys(coinList)" :label="coinList[item]"
                                :value="Number(item)" />
                        </el-select>
                    </el-form-item>
                    <el-form-item>
                        <label>状态：</label>
                        <el-select v-model="state" placeholder="请选择">
                            <el-option v-for="item in Object.keys(WithdrawStateList)" :label="WithdrawStateList[item]"
                                :value="Number(item)" />
                        </el-select>
                    </el-form-item>
                    <el-form-item>
                        <el-date-picker v-model="dateTime" type="daterange" range-separator="至"
                            value-format="yyyy-MM-dd" start-placeholder="开始日期" end-placeholder="结束日期" />
                    </el-form-item>
                    <el-form-item>
                        <el-button type="primary" @click="onSearch">查询</el-button>
                    </el-form-item>
                </div>
                <div />
            </div>

            <el-form>
                <el-form-item>
                    <div style="font-size: 18px;font-weight: bold;">汇总:</div>
                    <div>
                        <div class="flex" style="margin-left: 20px;" v-if="total.USDT">
                            <div style="font-size: 14px;">USDT：</div>
                            <div>【 申请金额：{{ total.USDT.applyAmount }} 】</div>
                            <div>【 手续费：{{ total.USDT.fee }} 】</div>
                            <div>【 到账金额：{{ total.USDT.toAmount }} 】</div>
                        </div>
                        <div class="flex" style="margin-left: 20px;" v-if="total.ALEO">
                            <div style="font-size: 14px;">ALEO：</div>
                            <div>【 申请金额：{{ total.ALEO.applyAmount }} 】</div>
                            <div>【 手续费：{{ total.ALEO.fee }} 】</div>
                            <div>【 到账金额：{{ total.ALEO.toAmount }} 】</div>
                        </div>
                        <div class="flex" style="margin-left: 20px;" v-if="total.AL1">
                            <div style="font-size: 14px;">AL1：</div>
                            <div>【 申请金额：{{ total.AL1.applyAmount }} 】</div>
                            <div>【 手续费：{{ total.AL1.fee }} 】</div>
                            <div>【 到账金额：{{ total.AL1.toAmount }} 】</div>
                        </div>
                        <div class="flex" style="margin-left: 20px;" v-if="total.AL2">
                            <div style="font-size: 14px;">AL2：</div>
                            <div>【 申请金额：{{ total.AL2.applyAmount }} 】</div>
                            <div>【 手续费：{{ total.AL2.fee }} 】</div>
                            <div>【 到账金额：{{ total.AL2.toAmount }} 】</div>
                        </div>
                    </div>
                </el-form-item>
            </el-form>
        </el-form>
        <!-- 列表数据 -->
        <el-table v-loading="listLoading" :data="tableData" border style="width: 100%">
            <el-table-column prop="userId" label="用户ID" align="center" width="80" />
            <el-table-column prop="fromUserName" label="用户账号" align="center" />
            <el-table-column prop="coin_str" label="币种" align="center" />
            <el-table-column prop="applyAmount" label="提现申请金额" align="center" />
            <el-table-column prop="fee" label="手续费" align="center" />
            <el-table-column prop="toAmount" label="实际到账" align="center" />
            <el-table-column prop="fromAddr" label="来源地址" align="center" />
            <el-table-column prop="toAddr" label="收款地址" align="center" />
            <el-table-column prop="tradehash" label="交易hash" align="center" />
            <el-table-column prop="state_str" label="状态" align="center" />
            <el-table-column prop="remark" label="驳回原因" align="center" />
            <el-table-column prop="etime_str" label="打款/驳回时间" align="center" />
            <el-table-column prop="ctime_str" label="提现申请时间" align="center" />
            <!-- <el-table-column label="操作" width="150" align="center">
                <template slot-scope="scope">
                    <el-button size="mini" type="primary"
                        @click="$router.push({ name: 'BalanceRecord', query: { tradetype: '6' } })">系统充值</el-button>
                </template>
</el-table-column> -->
        </el-table>
        <!-- 分页 -->
        <div class="block " style="padding-top: 20px;">
            <el-pagination background :current-page="pageIndex" :page-sizes="[10, 20, 30, 40]" :page-size="pageSize"
                layout="total, sizes, prev, pager, next, jumper" :total="totalCount"
                @size-change="idx => { pageSize = idx }" @current-change="idx => { pageIndex = idx }" />
        </div>
    </div>
</template>

<script>
import { WithdrawPage } from '@/api/users.js'
import { GetEnum } from "@/api/ctrls.js";
import { formatDate } from '@/utils/index.js'
export default {
    name: 'Name',
    data() {
        return {
            dateTime: [], // 时间查询
            userid: '',
            key: '',
            stime: '', // 开始时间 2022-01-01
            etime: '', // 结束时间
            coinid: 0, // 币种ID
            state: -1,


            listLoading: false,
            tableData: [],
            totalCount: 0,
            pageIndex: 1,
            pageSize: 20,
            total:{},


            WithdrawStateList: {},
            coinList: {}
        }
    },
    computed: {
        // ...mapState({
        //   tradetypeList: state => state.user.enumList["TradeType"]
        // })
    },
    watch: {
        pageIndex(val) {
            console.log(val)
            this.getData()
        },
        pageSize(val) {
            console.log(val)
            this.getData()
        }
    },
    async created() {
        if (this.$route.query.ctime) {
            let tiemIndex = this.$route.query.ctime.indexOf("T");
            this.dateTime[1] = this.$route.query.ctime.substring(0, tiemIndex)
            this.dateTime[0] = this.$route.query.ctime.substring(0, tiemIndex)
        }
        if (this.$route.query.type == '0') {
            this.state = 0;
        }
        if (this.$route.query.time) {
            this.dateTime[0] = formatDate(new Date(), 'yyyy-MM-dd')
            this.dateTime[1] = formatDate(new Date(), 'yyyy-MM-dd')
        }
        this.getData()
        this.GetEnum();
    },
    methods: {
        // 获取枚举
        async GetEnum() {
            const res = await GetEnum();
            this.coinList = res.data['Coin'];
            this.WithdrawStateList = res.data['WithdrawState'];
        },
        async onSearch() {
            this.PageIndex = 1
            this.getData()
        },
        // 获取数据
        async getData() {
            this.listLoading = true
            const { list, totalCount,total } = await WithdrawPage({
                userid: this.userid,
                key: this.key,
                coinid: this.coinid,
                state: this.state,
                stime: this.dateTime ? this.dateTime[0] : '',
                etime: this.dateTime ? this.dateTime[1] : '',
                pageIndex: this.pageIndex,
                pageSize: this.pageSize
            })
            this.totalCount = totalCount
            this.total = total
            this.tableData = list
            this.listLoading = false
        }
    }
}
</script>

<style lang="scss">
.el-table .warning-row {
    background: oldlace;
}
</style>